/*
 *    This file is part of CeluMap.
 *
 *    CeluMap is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    CeluMap is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    Copyright 2006, 2007, 2008 Gonzalo Merayo
 *    gonzalo (at) celumap.com.ar
 *    www.celumap.com.ar
 *
 */

package indexWriters;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.TreeMap;

import map.file.FileMap;

import figures.Figure;
import geometry.Rectangle;

public class FileIndexWriter implements IndexWriter {

	TreeMap<Integer, String> nombres = new TreeMap<Integer, String>();
	TreeMap<Integer, Rectangle> ubicaciones = new TreeMap<Integer, Rectangle>();

	public void write(DataOutputStream dos) throws IOException {
		for(Integer i:nombres.keySet()){
			dos.writeInt(i);
			FileMap.writeString(dos, nombres.get(i));
			ubicaciones.get(i).unload(dos);
		}
	}

	public void addItem(Figure id, String nombre) {
		if(nombre != null){
			nombres.put(id.getId(), nombre);
			ubicaciones.put(id.getId(), id.getBoundingBox());
		}
	}

}
